//
//  XLCommitPictureCell.m
//  XiangLove
//
//  Created by 宋振 on 2018/8/10.
//  Copyright © 2018年 BAOMIHUA.COM. All rights reserved.
//

#import "XLCommitPictureCell.h"

#import <UIImage+WebP.h>

@interface XLCommitPictureCell ()

/**
 上传图片
 */
@property (nonatomic, strong) UIImageView *  pictureView;

//认证头像
@property (nonatomic, strong) UIImageView *  startView;

@end

@implementation XLCommitPictureCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:(CGRect)frame];
    
    if (self) {
        
        [self initUI];
        
    }
    
    return self;
}

#pragma mark    - - - Init UI - - -

/**
 绘制
 */
- (void)initUI
{
    //设置头像显示
    [self.contentView addSubview:self.pictureView];
    
    [self.pictureView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
    
    //设置头像标志
    [self.contentView addSubview:self.startView];
    
    [self.startView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.and.bottom.equalTo(self.pictureView);
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];
}

#pragma mark    - - - 数据加载 - - -

- (void)setDataDic:(NSDictionary *)dataDic
{
    _dataDic = dataDic;
    
    if (dataDic) {
        
        NSString *isHeadeImg = [NSString stringWithFormat:@"%@",dataDic[@"IsHeadImage"]];
        
        NSString *url = K_DEFULT(dataDic[@"Url"]);
        
        if ([isHeadeImg isEqualToString:@"1"]) {
            
            self.startView.hidden = NO;
            
        }else{
            self.startView.hidden = YES;
        }
        
        [self.pictureView sd_setImageWithURL:[NSURL URLWithString:K_DEFULT(url)] placeholderImage:[UIImage imageNamed:@"common_pic_tianjia1"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
            
            self.pictureView.image = image;
            
        }];
        
    }else{
        self.pictureView.image = [UIImage imageNamed:@"common_pic_tianjia1"];
        self.startView.hidden = YES;
    }
}







#pragma mark    - - - 懒加载 - - -

- (UIImageView *)pictureView
{
    if (!_pictureView) {
        self.pictureView = [[UIImageView alloc] init];
        self.pictureView.image = [[UIImage imageNamed:@"common_pic_tianjia1"] imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)];
        self.pictureView.layer.cornerRadius = 3;
        self.pictureView.layer.masksToBounds = YES;
    }
    
    return _pictureView;
}

- (UIImageView *)startView
{
    if (!_startView) {
        self.startView = [[UIImageView alloc] init];
        self.startView.image = [UIImage imageNamed:@"common_icon_xx"];
        self.startView.hidden = YES;
    }
    
    return _startView;
}









@end
